package study.itheima.stusys;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/*@WebFilter("/webstu/index.jsp")
public class LoginFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("Text/Html;charset=UTF-8");
        String username = servletRequest.getParameter("username");
        String contextPath = servletRequest.getServletContext().getContextPath();
        if (username.equals("")){
            ((HttpServletResponse)servletResponse).sendRedirect(contextPath+"/webstu/login.jsp");
        }else {
            HttpSession session = ((HttpServletRequest) servletRequest).getSession();
            session.setAttribute("username",username);
            filterChain.doFilter(servletRequest,servletResponse);
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
*/